<!DOCTYPE html>
<html>
<head>
<#include "/freemarker/fw/meta_top.ftl">
    <title>${book.bookname} | 编写章节</title>
<#include "/freemarker/fw/load_static.ftl">
    <script src="/asset/ueditor/ueditor.config.js"></script>
    <script src="http://ueditor.baidu.com/ueditor/ueditor.all.js"></script>
</head>
<body>
<#include "/freemarker/fw/navbar_top.ftl">
<div class="container-fluid">
    <div class="row">
        <div class="col-lg-7">
            <p>
                <input class="center-block btn-block" type="text" style="width: 100%;" name="title" placeholder="章节标题">
            </p>

            <div>
                <script type="text/plain" id="editor">输入内容</script>
            </div>
            <p>
                <button style="margin: 10px 0;" class="btn btn-default btn-block" type="submit">提交</button>
            </p>
        </div>
        <div class="col-lg-5">
            <h4 style="text-align: center;">${book.bookname}</h4>
        </div>
    </div>
    <script>
        $(document).ready(function () {
            var editor = new UE.getEditor("editor");
            $("button[type='submit']").on("click", function(){
                var jqxhr = $.post("/chapter/create/${book.getInt("id")}",{
                    title: $("input[name='title']").val(),
                    text: editor.getContent()
                });
                jqxhr.done(function(response){
                    window.location.href = "/chapter/" + response.id;
                });
            })
        })
    </script>
</div>
</body>
</html>